/// 分页数据模型
class PaginationData {
  final int total;
  final int page;
  final int limit;
  final int totalPages;

  PaginationData({
    required this.total,
    required this.page,
    required this.limit,
    required this.totalPages,
  });

  /// 从JSON创建实例
  factory PaginationData.fromJson(Map<String, dynamic> json) {
    return PaginationData(
      total: json['total'] ?? 0,
      page: json['page'] ?? 1,
      limit: json['limit'] ?? 50,
      totalPages: json['total_pages'] ?? 1,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'total': total,
      'page': page,
      'limit': limit,
      'total_pages': totalPages,
    };
  }

  /// 判断是否还有下一页
  bool get hasNextPage {
    return page < totalPages;
  }

  /// 判断是否有上一页
  bool get hasPreviousPage {
    return page > 1;
  }

  /// 获取下一页页码
  int? get nextPage {
    return hasNextPage ? page + 1 : null;
  }

  /// 获取上一页页码
  int? get previousPage {
    return hasPreviousPage ? page - 1 : null;
  }

  /// 获取当前页开始记录的索引（从1开始）
  int get startRecord {
    return (page - 1) * limit + 1;
  }

  /// 获取当前页结束记录的索引
  int get endRecord {
    final end = page * limit;
    return end > total ? total : end;
  }

  /// 获取分页信息描述
  String get description {
    if (total == 0) return '暂无数据';
    return '第${startRecord}-${endRecord}条，共${total}条';
  }

  @override
  String toString() {
    return 'PaginationData{total: $total, page: $page, limit: $limit, totalPages: $totalPages}';
  }
}
